import React, {Component, PropTypes} from 'react';
import {inject, observer} from 'mobx-react';
import {WeaDialog, WeaTools} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
import FavouriteDir from './dir/index';
import SysFavourite from './favourite/index';
import SearchFavourite from '../util/SearchFavourite';
import '../style/index.css';
import '../style/tree.less';

@inject('myFavouriteStore')
@inject('favouriteDirStore')
@inject('sysFavouriteStore')

@observer
class FullpageTree extends Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        const {myFavouriteStore, favouriteDirStore, sysFavouriteStore} = this.props;
        // 页面初始化的一些数据
        myFavouriteStore.initPage();
        // 先将树原本的数据清空
        favouriteDirStore.initTree();
        // 加载左侧目录树的数据
        favouriteDirStore.loadTreedata('0');
        // favouriteDirStore.loadTree("0");
        // 初始化加载收藏内容第一页的数据
        const isinit = true;
        const searchFavourite = new SearchFavourite(sysFavouriteStore);
        searchFavourite.reset(); // 先初始化收藏的条件
        searchFavourite.set;
        searchFavourite.load({isinit});
    }


    render() {
        const {className} = this.props;
        return (
            <div className={className}>
                <FavouriteDir ecId={`${this && this.props && this.props.ecId || ''}_FavouriteDir@2xcna6`}
                              changename="fullPagetreeLeft"/>
                <SysFavourite ecId={`${this && this.props && this.props.ecId || ''}_SysFavourite@seview`}
                              changename="fullPagetreeRight"/>
            </div>
        );
    }
}

class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== '';
        return (
            <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@dzrbhu`}
                          msg={hasErrorMsg ? this.props.error : `${getLabel(385218, '对不起，该页面异常，请联系管理员！')}`}/>
        );
    }
}

FullpageTree = WeaTools.tryCatch(React, MyErrorHandler, {error: ''})(FullpageTree);

export default FullpageTree;
